

/**
 * @file    sparkai.h
 * @author  Azolla (1228449928@qq.com)
 * @brief   
 * @version 0.1
 * @date    2023-02-06
 * 
 * @copyright Copyright (c) 2023
 * */
#ifndef __SPARKAI__H__
#define __SPARKAI_H__

#define SPARKAI_MAX_TOKENS      1280    // 模型回答的tokens的最大长度[1,4096] (语音合成：1280)
#define SPARKAI_THRESHOLD       0.5     // 核采样阈值; 取值范围 (0，1] ，默认值0.5

#include "esp_heap_caps.h"
#define AI_MEMORY_CAPS_TYPE         (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)  // PSRAM
// #define AI_MEMORY_CAPS_TYPE     (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)     // RAM
#define ai_memory_malloc(size)      heap_caps_malloc(size, AI_MEMORY_CAPS_TYPE)
#define ai_memory_calloc(n, size)   heap_caps_calloc(n, size, AI_MEMORY_CAPS_TYPE)
#define ai_memory_realloc(size)     heap_caps_realloc(ptr, size, AI_MEMORY_CAPS_TYPE)
#define ai_memory_free(ptr)         heap_caps_free(ptr)

// status: 取值范围为：0（开始）、1（继续）、2（结束）
typedef enum {
    SPARKAI_STATUE_BEGIN = 0X00,
    SPARKAI_STATUE_KEEP  = 0X01,
    SPARKAI_STATUE_OVER  = 0X02,
} sparkai_status_t; 

// 选择哪个模型 
typedef enum {
    SPARKAI_MODEL = 0X01,   // 星火AI大模型
    AUDIOAI_MODEL = 0X02    // 语音识别模型
} sparkai_model_t; 

typedef struct {
    uint8_t status;
    uint8_t seq;
    char    text[SPARKAI_MAX_TOKENS];
} sparkai_accept_t, audioai_accept_t;
 


// typedef struct {
//     uint8_t status;
//     uint8_t seq;
//     char    text[SPARKAI_MAX_TOKENS];
// } audioai_accept_t;

typedef struct {
    // uint8_t  pcm[SPARKAI_MAX_TOKENS];
    uint8_t *pcm;
    uint16_t size;
    uint8_t  status;
    uint16_t seq;
} audioai_request_t;

void sparkai_init(void);

void sparkai_create_url(char *url);

void audioai_create_url(char *url);

bool audioai_speech_over(void);

int sparkai_request(void *msg, sparkai_model_t mode);

void audioai_req_handler(bool action, void *pcm, uint16_t size);

#endif  /*__SPARKAI_H__ END.*/